package js;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

import util.Config;
import util.DBUtils;

public class CheckGatewayMain {

	private static Logger log = LogManager.getLogger(CheckGatewayMain.class);

	private DBUtils dbUtils = null;
	private Connection conn = null;

	CheckGatewayMain(){
		dbUtils = new DBUtils();
		conn = dbUtils.getConn();
	}

	public static void main(String[] args) {
		CheckGatewayMain cGatewayMain = new CheckGatewayMain();
		cGatewayMain.insertWarnSmsToBosssmSend("�Ŷ��Ͼ���ӭ�����Ͼ�������ίԱ����ܰ��ʾ���������Σ�ƽ�����С�","14");
		cGatewayMain.insertWarnSmsToBosssmSend("׾��԰��ӭ���ĵ���!��������׾��԰������","11");

	}

	private void insertWarnSmsToBosssmSend(String content,String city_id){

		PreparedStatement pres = null;
		String result = "-1";
		String fetch_id = "";
		String sql = "insert into boss_sm_send(id,receiver,sender,content,result,create_date,modify_date,fetch_id,city_id)" +
				"values(seq_bomc_cmpp.nextval,?,?,?,?,sysdate,sysdate,?,?)";
		try {
			if(conn == null){
				conn = dbUtils.getConn();
			}
			conn.setAutoCommit(false);
			pres = conn.prepareStatement(sql);
			String[] str = null;
			str = Config.receiver.split(",");
			for (int i = 0; i < str.length; i++) {
				pres.setString(1, str[i]);
				pres.setString(2, Config.sender);
				pres.setString(3, content);
				pres.setString(4, result);
				pres.setString(5, fetch_id);
				pres.setString(6, city_id);
				pres.addBatch();
			}
			pres.executeBatch();
			conn.commit();
		} catch (SQLException e) {
			log.error("����澯���������ŷ��ͱ�����쳣������");
			e.printStackTrace();
		} finally{
			close(pres, null);
		}
	}

	/**
	 * �ر�Ԥ����ͽ�����ͷ���Դ
	 */
	private void close(PreparedStatement pres,ResultSet rs){
		try {
			if(rs!=null){
				rs.close();
			}
			if(pres!=null){
				pres.close();
			}
		} catch (Exception e) {
			log.error("�رս���������쳣" + e.fillInStackTrace());
		}
	}

}
